<?php
class TdFieldset extends TdFormField {
  var $fields = array();
  var $name;

  function __construct($id, $template="") {
    parent::__construct($id, $template);
  }

  function addField($field) {
  	$field->setForm($this->form);
    $this->fields[$field->id] = $field;
  }

  function getField($id) {
  	return $this->fields[$id];
  }
  
  function __toString() {
  	$pout = parent::__toString();
  	if ($pout != "") {
  		return $pout;
  	}
  	 
    ob_start();
    print("<fieldset class=\"".$this->cssclass."\" id=\"".$this->id."\" name=\"".$this->name."\">");
    foreach ($this->fields as $field) {
      print($field);
    }
    print("</fieldset>");

    return ob_get_clean();
  }
  
  function doValidate() {
  	foreach ($this->fields as $id => $obj) {
  		$obj->doValidate();
  		if ($obj->gotError()) {
  			$emsg = $this->getErrorMessage();
  			if ($emsg != "") $emsg .= " | ";
  			$emsg .= $obj->getErrorMessage();
  		  $this->setErrorMessage($emsg);
  		}
  	}
  }

  function setName($value) {
  	$this->name = $value;
  }
  function getName() {
  	return $this->name;
  }
  
}

?>
